layui.use(['form','layer','jquery'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer
        $ = layui.jquery;

    //ajax登录
    function submitForm() {
        var username = $('#username').val();
        var passwprd = $('#password').val();
        $.ajax({
            url:'/login',
            type:'post',
            dataType : "JSON",
            contentType:'application/json',
            data:JSON.stringify({'username':username,'password':passwprd}),
            success:function (res) {
                console.log(res)
                if(res.success == true)
                {
                    window.location.href = '/';
                }
            }
        })
    }

    //登录按钮
    $("#login").click(function(){
        submitForm()
    })

    //表单输入效果
    $(".loginBody .input-item").click(function(e){
        e.stopPropagation();
        $(this).addClass("layui-input-focus").find(".layui-input").focus();
    })
    $(".loginBody .layui-form-item .layui-input").focus(function(){
        $(this).parent().addClass("layui-input-focus");
    })
    $(".loginBody .layui-form-item .layui-input").blur(function(){
        $(this).parent().removeClass("layui-input-focus");
        if($(this).val() != ''){
            $(this).parent().addClass("layui-input-active");
        }else{
            $(this).parent().removeClass("layui-input-active");
        }
    })
})
